import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
import java.nio.charset.StandardCharsets;

public class demon1 {
    private DatagramSocket datagramSocket=null;
    public demon1(int port){
        try {
            datagramSocket = new DatagramSocket();
        } catch (SocketException e) {
            e.printStackTrace();
        }

    }
    public void start(){
        System.out.println("服务区启动");
        while(true){
            DatagramPacket requesrdatagramPacket=new DatagramPacket(new byte[4090],4090 );
            try {
                datagramSocket.receive(requesrdatagramPacket);
            } catch (IOException e) {
                e.printStackTrace();
            }
            String resp=new String(requesrdatagramPacket.getData(),0,requesrdatagramPacket.getLength());
            String respon=process(resp);
            DatagramPacket datagramPacket=new DatagramPacket(respon.getBytes(),respon.getBytes().length,
                    requesrdatagramPacket.getSocketAddress());
            try {
                datagramSocket.send(datagramPacket);
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("[%s]");
        }
    }

    private String process(String resp) {
        return resp;
    }
}
